package com.zhongge.operations;

import com.zhongge.book.Book;
import com.zhongge.book.BookList;

import java.util.Scanner;

@SuppressWarnings("all")
/**
 * @ClassName SearchBook
 * @Description TODO 查找图书
 * @Author zhongge
 * @Date 2025/7/14 19:28
 * @Version 1.0
 */
public class SearchBook implements IOperation{
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你的书名：");
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getBook(i);
            //查找
            if (name.equals(book.getName())) {
                System.out.println("查找成功：");
                System.out.println(book);
                return;
            }
        }
        //程序走到这里：查找失败
        System.out.println("查找失败");
    }
}
